package com.eportal.util;
import org.apache.log4j.Logger;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * 发送邮件属性配置类
 * Created by smzhang on 2015/12/16.
 */
public class MailProperty {

    private static Logger log = Logger.getLogger(MailProperty.class);

    public static final String ENCODEING = "UTF-8";

    private String host; // 服务器地址

    private String protocol;

    private String sender; // 发件人的邮箱

    private String name; // 发件人昵称

    private String username; // 账号

    private String password; // 密码

    private MailProperty() {}

    private static MailProperty mailProperty;

    public static MailProperty getMailProperty() {
        if (mailProperty == null) {
            // 加载配置文件
            //InputStream in = MailProperty.class.getResourceAsStream("/com/eportal/email/email.properties");
        	InputStream in = MailProperty.class.getResourceAsStream("/email.properties");
            Properties prop = new Properties();
            try {
                prop.load(in);
                mailProperty = new MailProperty();
                mailProperty.setHost(prop.getProperty("host"));
                mailProperty.setProtocol(prop.getProperty("protocol"));
                mailProperty.setAuth(prop.getProperty("auth"));
                mailProperty.setSender(prop.getProperty("sender"));
                mailProperty.setUsername(prop.getProperty("username"));
                mailProperty.setPassword(prop.getProperty("password"));
            } catch (IOException e) {
                log.error("MailProperty属性加载失败",e);
            }

        }
        return mailProperty;
    }

    private String auth;

    public String getAuth() {
        return auth;
    }

    public void setAuth(String auth) {
        this.auth = auth;
    }

    public String getProtocol() {
        return protocol;
    }

    public void setProtocol(String protocol) {
        this.protocol = protocol;
    }

    public String getHost() {
        return host;
    }

    public void setHost(String host) {
        this.host = host;
    }

    public String getSender() {
        return sender;
    }

    public void setSender(String sender) {
        this.sender = sender;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }


    public static void main(String[] args) {
        getMailProperty();
    }


}
